<div class="bjui-pageContent">
    <form action="/admin/company/address-edit" data-toggle="ajaxform" data-options="{closeCurrent:true,tabid:'address-lists'}">
        <div class="bjui-row">

            <label class="row-label">选择客户</label>
            <div class="row-input">
                <select name="foreign_key" id="foreign_key" data-toggle="selectpicker"data-rule="required">
                    <option value="">请选择</option>
                    @foreach ($foreignList as $val)
                        @if ($info['foreign_key'] == $val['id'])
                            <option value="{{$val['id']}}" selected>{{$val['customer_name']}}</option>
                        @else
                            <option value="{{$val['id']}}">{{$val['customer_name']}}</option>
                        @endif
                    @endforeach
                </select>
            </div>
            <label class="row-label">手机号</label>
            <div class="row-input">
                <input type="text" name="phone" value="{{$info['phone']}}">
            </div>
            <label class="row-label">选择省</label>
            <div class="row-input">
                <select name="province_id" id="province_id" data-toggle="selectpicker"data-rule="required">
                    <option value="">请选择</option>
                    @foreach ($provinceList as $val)
                        @if ($info['province_id'] == $val['provinceID'])
                            <option value="{{$val['provinceID']}}" selected>{{$val['province']}}</option>
                        @else
                            <option value="{{$val['provinceID']}}">{{$val['province']}}</option>
                        @endif
                    @endforeach
                </select>
            </div>
            <label class="row-label">选择市</label>
            <div class="row-input">
                <select name="city_id" id="city_id" data-rule="required">
                    <option value="">请选择</option>
                    @if (!empty($info['city_id']) && $info['city_id']>0)
                        <option value="{{$info['city_id']}}" selected>{{$info['city_name']}}</option>
                    @endif
                </select>
            </div>
            <label class="row-label">选择县</label>
            <div class="row-input">
                <select name="area_id" id="area_id" data-rule="required">
                    <option value="">请选择</option>
                    @if (!empty($info['area_id']) && $info['area_id']>0)
                        <option value="{{$info['area_id']}}" selected>{{$info['area_name']}}</option>
                    @endif
                </select>
            </div>
            <label class="row-label">详细地址</label>
            <div class="row-input">
                <input type="text" name="address" value="{{$info['address']}}">
            </div>
            <input type="hidden" name="consignee" id="consignee" value="{{$info['consignee']}}">
            <input type="hidden" name="province_name" id="province_name" value="{{$info['province_name']}}">
            <input type="hidden" name="city_name" id="city_name" value="{{$info['city_name']}}">
            <input type="hidden" name="area_name" id="area_name" value="{{$info['area_name']}}">
            <input type="hidden" name="id" id="id" value="{{$info['id']}}">

            <label class="row-label"></label>
            <div class="row-input">
                <input type="hidden" name="is_submit" id="is_submit" value="1">
                <button type="submit" class="btn-default">保存</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $('#foreign_key').change(function(){
        var value       = $(this).val();
        var text        = $(this).find("option:selected").text();
        $('#consignee').val(text);
    });
    $('#province_id').change(function(){
        var value       = $(this).val();
        addressChangeCity(value);
        var text        = $(this).find("option:selected").text();
        $('#province_name').val(text);
    });
    $('#city_id').change(function(){
        var value       = $(this).val();
        addressChangeArea(value);
        var text        = $(this).find("option:selected").text();
        $('#city_name').val(text);
    });
    $('#area_id').change(function(){
        var text        = $(this).find("option:selected").text();
        $('#area_name').val(text);
    });
    function addressChangeCity(value)
    {
        if(value!=''){
            var url     = 'admin/company/address-ajaxAreaList';
            var obj     = {type:2,value:value};
            $.post(url,obj,function(data){
                var html    = '<option value="">请选择</option>';
                $.each(data,function(i,n){
                    html    += '<option value="'+n.cityID+'">'+n.city+'</option>';
                })
                $('#city_id').html(html);
            },'json');
        } else {
            var html    = '<option value="">请选择</option>';
            $('#city_id').html(html);
            $('#area_id').html(html);
            return false;
        }
    }
    function addressChangeArea(value)
    {
        if(value!=''){
            var url     = 'admin/company/address-ajaxAreaList';
            var obj     = {type:3,value:value};
            $.post(url,obj,function(data){
                var html    = '<option value="">请选择</option>';
                $.each(data,function(i,n){
                    html    += '<option value="'+n.areaID+'">'+n.area+'</option>';
                })
                $('#area_id').html(html);
            },'json');
        } else {
            var html    = '<option value="">请选择</option>';
            $('#area_id').html(html);
            return false;
        }
    }
</script>